<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta name="author" content="wangyuguo">
		<title>单位帐户维护</title>
		<script language="javascript" src="../script/common.js" type="text/javascript"></script>
		<script language="javascript" src="../script/card.js" type="text/javascript"></script>
		<script type="text/javascript" language="JavaScript" src="../script/tree.js"></script>
		
		<!--动态js-->
<script type="text/javascript">
	//页面加载方法
	var data;
	var opts;
	var cOrg;
	var tabs = {											//不同的tab触发的方法
			"customer":{name:"tab_customer",text:"档案信息",tabFunc:showCustomer},
			"carduser":{name:"tab_carduser",text:"帐号信息",tabFunc:showCardUser},
			"dept":{name:"tab_dept",text:"部门信息",tabFunc:showDept},
			"drivers":{name:"tab_drivers",text:"司机信息",tabFunc:showDrivers}
		};
	
	function load(){
		Eui.showNavigation();											// 显示导航栏
		setPages(["customerview","carduserview","deptview","driversview","limitview","deptlimitview"]);					//切换页面
		cOrg = Common.cOrg();
		opts = {};
		Eui.buildTabs("tabsdiv",tabs);
		$("tab_customer").onclick();
	}		
		
	//读卡
	function onReadCard(){
		try{
			getCard();
			var asn = getAsn();
			data = DWR.syncCall("mgntQueryService.findOkCompanyUser",asn);
			
			var cardType = data.cardType;
			var cardUser = data.cardUser;
			
			if (!CardMgnt.checkCompanyLocation(cardUser)) return;
			
			Common.setValues(companyUserViewForm,CardMgnt.parseCardUser(data));
			$("readMasterCardBtn").disabled = true;
			$("saveBtn").disabled = false;
			opts.companyUserId = cardUser.id;
			$("tab_customer").onclick();
		}catch(e){
			showError(e.description);
			onCancel();
		}
	}
	
	function showCustomer(){
		switchPage("customerview");
		CardMgnt.customer.saveHandle = function(companyCustomer){
			data.companyCustomer = companyCustomer;
		}
		CardMgnt.customer.isCompany = true;
		CardMgnt.customer.showCustomer("customerdiv",data?data.companyCustomer:null,CardMgnt.COMPANYALL,{showAll:true});
	}
	
	function showCardUser(){
		if (!data) throw new Error("请先读主卡，查询单位客户帐户信息");
		switchPage("carduserview")
		CardMgnt.cardUser.saveHandle = function(cardUser){
			data.cardUser = cardUser;
		}
		CardMgnt.cardUser.showData("carduserdiv",data,CardMgnt.COMPANYALL);
	}
	function showDept(){			//编辑页面
		if (!data) throw new Error("请先读主卡，查询单位客户帐户信息");
		switchPage("deptview");
		CardMgnt.dept.showData("deptview",data);
	}
	
	function showDrivers(){
		if (!data) throw new Error("请先读主卡，查询单位客户帐户信息");
		switchPage("driversview");
		var options = {}
		options.notAdd = true;
		options.operatRender = function(v,r){
			var status = r[9];
			var str = "";
			if (status == CardUserStatus.UNACTIVATED || status == CardUserStatus.OK){
				str += "<a href=# onclick=\"CardMgnt.drivers.showDet("+r[0]+");return false;\">编辑</a>";
				if (status == CardUserStatus.OK)
					str += " <a href=# onclick=\"syncCardData('"+r[5]+"',"+r[10]+");return false;\">同步卡数据</a>"
			}else
				str += "--";
			return str;
		}
		CardMgnt.drivers.showList("driverlistdiv",opts.companyUserId,null,options)
	}
	
	
	//重置
	function onCancel(){
		data=null;
		$(CardMgnt.customer.formName).reset();
		$("tab_customer").onclick();
		companyUserViewForm.reset();
		$("readMasterCardBtn").disabled = false;
		$("saveBtn").disabled = true;
	}
	//同步司机卡片数据方法
	function syncCardData(asn,usePin){
		if (!showQuestion("是否同步卡片"+asn+"的数据？")) return;
		var pin;
		try{
			getCard();
			if (asn != getAsn())
				throw new Error("不是该帐户的卡片，不能同步卡数据！");
		}catch(e){showError(e.description);return;}
			
		var cPin = getNeedPin();
		
		var getText = function(c){
			return c ? "启用":"停用"
		}
		
		if (usePin != cPin){
			showWarning("卡内密码标志("+getText(cPin)+")与后台密码标志("+getText(usePin)+")不一致，<br>需先"+getText(usePin)+"卡密码！");
			try{
				var res = CardMgnt._usePinApp(asn,usePin,pin);
				pin = res.pin;
			}catch(e){showError(e.description);return;}
		}else{
			pin = CardMgnt.inputCardPin();
		}
		
		if (!pin) return;
	
		while(true){
			try{
				CardMgnt.syncCardData(asn,pin);
				showInformation("同步卡数据成功");
				break;
			}catch(e){
				if (showQuestion("同步卡数据失败！是否重试？<br>错误："+e.description)){
					continue;
				}
				return;
			}
		}
	}
</script>

	</head>
	
<body onload="load()">
	<div class="nav"><div id="nav">&nbsp;</div></div>
	<div class="form">
		<div class="formTitle">单位帐号信息</div>
		<form id="companyUserViewForm" name="companyUserViewForm">
			<input type="hidden" name="cardType">
			<table cellSpacing="0" cellPadding="4" width="100%" border="0" class="col4 label4">
				<tr>
					<td><label>单位名称</label> <input name="name" type="text" readonly class="readonly"></td>
					<td><label>证件类型</label> <input name="idnoTypeText" type="text" readonly class="readonly"></td>
					<td><label>证&nbsp;件&nbsp;号</label> <input name="idno" type="text" readonly class="readonly"></td>
					<td><label>客户编号</label> <input name="uniqueId" type="text" readonly class="readonly"></td>
				</tr>
				<tr>
					<td><label>开户机构</label> <input name="buildFileStation" type="text" readonly class="readonly"></td>
					<td><label>状&nbsp;&nbsp;&nbsp;&nbsp;态</label> <input name="statusText" type="text" readonly class="readonly"></td>
					<td><label>客户级别</label> <input name="currentLevelText" type="text" readonly class="readonly"></td>
					<td><label>卡片类型</label> <input name="cardTypeName" type="text" readonly class="readonly"></td>
				</tr>
			</table>
		</form>
	</div>
	<div class="width97">
		<div id='tabsdiv' align="left"></div>
		<div id="customerview">
			<div id="customerdiv" class="form"></div>
			<p>
				<button id="readMasterCardBtn" onclick="onReadCard()">读主卡</button>
				<button id="saveBtn" onclick="CardMgnt.customer.save()" disabled>保存档案</button>
				<button onclick="onCancel()">重 置</button>
			</p>
		</div>
		<div id="carduserview" style="display:none;">
			<div id="carduserdiv" class="form"></div>
			<p>
				<button onclick="CardMgnt.cardUser.save()">保存帐户</button>
				<button onclick="onCancel()">重 置</button>
			</p>
		</div>
	</div>
	<div>
		<div id="deptview" style="display:none;" class="w97border">
		</div>
		<div id="driversview" style="margin-top:-10px;display:none;">
			<div id="driverlistdiv"></div>
		</div>
	</div>
</body>
</html>
